// 某个模块的数据请求（增删改查！）

import $axios from "@/common/http";  // 封装的axios
import axios from "axios"   // 原生的axios
import { Message } from "element-ui"  // 提示框


export async function getRole(id) {
    // 读列表（树形、不是树形）   读某一个
    let res;
    if (id) {
        res = await $axios.get("/roleinfo", { params: { id } });
    } else {
        res = await $axios.get("/rolelist");  // 获取属性结构菜单！
    }
    return res.list;
}

export async function addRole(data) {
    let res = await $axios.post("/roleadd", data);
    Message.success(res.msg)
    return true;
}

export async function editRole(data) {
    let res = await $axios.post("/roleedit", data);
    Message.success(res.msg)
    return true;
}

export async function delRole(id) {
    if (!id) {
        Message.warning("请传入删除id");
        return;
    }
    let res = await $axios.post("/roledelete", { id })
    Message.success(res.msg)
    return res.list;
}